package com.abc.cloud.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.abc.cloud.common.utils.UserHolder;
import com.abc.cloud.dto.im.ContactsApplyResp;
import com.abc.cloud.vo.im.ContactsApplyExamineReq;
import com.abc.cloud.vo.im.ContactsApplyReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.abc.cloud.entity.ContactsApplyEntity;
import com.abc.cloud.service.ContactsApplyService;
import com.abc.cloud.common.utils.PageUtil;
import com.abc.cloud.common.utils.Result;



/**
 * 好友/群聊申请表
 *
 * @author LiJunXi
 * @email 2770063826@qq.com
 * @date 2023-11-29 13:19:41
 */
@Api("好友/群聊申请接口")
@RestController
@RequestMapping("/contactsApply")
public class ContactsApplyController {
    @Autowired
    private ContactsApplyService contactsApplyService;

    /**
     * 获取用户收到的申请列表
     */
    @ApiOperation(("获取用户收到的申请列表"))
    @GetMapping("/list")
    public Result<List<ContactsApplyResp>> list(){
        List<ContactsApplyResp> page = contactsApplyService.listApply();

        return Result.success(page, "获取成功");
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public Result info(@PathVariable("id") Long id){
		ContactsApplyEntity contactsApply = contactsApplyService.getById(id);

        return Result.success(contactsApply, "contactsApply");
    }

    /**
     * 保存
     */
    @ApiOperation("发送申请")
    @PostMapping("/save")
    public Result save(@RequestBody ContactsApplyReq contactsApplyReq){
        Long userId = UserHolder.getUser().getId();
        String username = UserHolder.getUser().getUsername();
		contactsApplyService.saveContactsApply(contactsApplyReq, userId, username);

        return Result.success(null, "申请成功");
    }

    /**
     * 用户审核申请
     */
    @ApiOperation("用户审核申请")
    @PutMapping("/examine")
    public Result examine(@RequestBody ContactsApplyExamineReq contactsApplyExamineReq){
        Long userId = UserHolder.getUser().getId();
        String username = UserHolder.getUser().getUsername();
		contactsApplyService.examineById(userId, username, contactsApplyExamineReq.getId(), contactsApplyExamineReq.getStatus(), contactsApplyExamineReq.getNote(), contactsApplyExamineReq.getGroupId());

        return Result.success(null, "操作成功");
    }

    /**
     * 删除
     */
    @ApiOperation("用户删除全部已操作申请")
    @PutMapping("/delete")
    public Result delete(){
        Long userId = UserHolder.getUser().getId();
		contactsApplyService.deleteAllOpContactsApply(userId, 4);

        return Result.success(null, "删除成功");
    }

}
